//
//  CAPageControl.m
//  cascade-realm
//
//  Created by QSC on 1/6/24.
//

#import "CAPageControl.h"

@implementation CAPageControl

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [Hex(0xDDFFFF) colorWithAlphaComponent:0.3];
       
        self.layer.cornerRadius = 6;
         
        

      
    }
    return self;
}

- (void)setCurrentPage:(NSInteger)currentPage{
    _currentPage = currentPage;
    [self reload];
}

- (void)setNumberOfPages:(NSInteger)numberOfPages{
    _numberOfPages = numberOfPages;
    [self reload];
}

- (void)reload{
    
    [self removeAllSubviews];
    
    CGFloat padding = 10;
    
    UIView * temp = [UIView new];
    for (int i = 0; i < self.numberOfPages; i++) {
        
        UIView * view = [UIView new];
        view.layer.cornerRadius = 2;
        if (i == _currentPage) {
            view.backgroundColor = Hex(0xB3E600);
        }else{
            view.backgroundColor = Hex(0xCCCCCC);
        }
        
        [self addSubview:view];
        
        CGFloat X = padding;
        if (i == 0) {
            X = padding;
        }else{
            X = temp.right + 4;
        }
        
        view.frame = CGRectMake(X, 0, i == self.currentPage?8:4, 4);
        view.centerY = 6;
        temp = view;
        
    }
    
    
}




@end
